import java.util.Hashtable;
import java.util.StringTokenizer;


class P11233_39643 {

	static String readLn() {
		String newLine = System.getProperty("line.separator");
		StringBuffer buffer = new StringBuffer();
		int car = -1;
		try {
			car = System.in.read();
			while ((car > 0) && (car != newLine.charAt(0))) {
				buffer.append((char) car);
				car = System.in.read();
			}
			if (car == newLine.charAt(0))
				System.in.skip(newLine.length() - 1);
		} catch (java.io.IOException e) {
			return (null);
		}
		if ((car < 0) && (buffer.length() == 0))
			return (null);
		return (buffer.toString());
	}

	
	public static void main(String[] args) {
		
		StringTokenizer st = new StringTokenizer(readLn());
		
		int l = Integer.parseInt(st.nextToken());
		int n = Integer.parseInt(st.nextToken());
		
		Hashtable table = new Hashtable();
		
		for (int k = 0; k < l; k++) {
			st = new StringTokenizer(readLn());
			String word = st.nextToken();
			String plural = st.nextToken();
			table.put(word, plural);
		}

		for (int k = 0; k < n; k++) {
			String word = readLn();
			
			String plural = (String) table.get(word);

//			   1.  If the word is in the list of irregular words replace it with the given plural.
//			   2. Else if the word ends in a consonant followed by "y", replace "y" with "ies".
//			   3. Else if the word ends in "o", "s", "ch", "sh" or "x", append "es" to the word.
//			   4. Else append "s" to the word.

//			System.out.print("> ");
			if (plural != null) {
				System.out.println(plural);
			} else if (word.length() > 1 && word.charAt(word.length() - 1) == 'y' && isConsonant(word.charAt(word.length() - 2))) {
				System.out.println(word.substring(0, word.length() - 1) + "ies");
			} else if (word.endsWith("o") || word.endsWith("s") || word.endsWith("ch") || 
						word.endsWith("sh") || word.endsWith("x")) {
				System.out.println(word + "es");
			} else {
				System.out.println(word + "s");
			}
			
			
		}
		
	}


	private static boolean isConsonant(char c) {
		
		if (c == 'a' || c == 'e' || c == 'i' || c == 'o' || c == 'u') return false;
		
		return true;
	}
	
}
